﻿using Asp.Versioning;
using Microsoft.Extensions.DependencyInjection;

namespace net.xBei.WebApi.FrameworkExtensions {
    /// <summary>
    /// 
    /// </summary>
    public static class ApiVersioningExtensions {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection SetupApiVersioning(this IServiceCollection services) {
            services.AddApiVersioning(setupAction => {
                setupAction.AssumeDefaultVersionWhenUnspecified = true;
                setupAction.DefaultApiVersion = new ApiVersion(1, 0);
            }).AddMvc()
            .AddApiExplorer(setup => {
                setup.GroupNameFormat = "'v'VVV";
                setup.SubstituteApiVersionInUrl = true;
            });
            return services;
        }
    }
}
